package com.management.service.Impl;

import com.management.dao.UserDao;
import com.management.po.User;
import com.management.service.UserService;
import com.management.tools.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author XS
 * 人员业务逻辑实现类
 * @version 1.0
 */
@Service
public class UserServiceImpl implements UserService{
    @Autowired
    UserDao userDao;
    @Override
    public List<User> findAll() {
        List<User> list = userDao.findAll();
        return list;
    }

    @Override
    public User findByUserId(int userId) {

        return userDao.findByUserId(userId);
    }

    @Override
    public List<User> find(User user) {
        return userDao.find(user);
    }

    @Override
    public User findByTelAndPass(String userTel, String userPassword) {
        String password=MD5Util.md5(userPassword);
        return userDao.findByTelAndPass(userTel, password);
    }

    @Override
    public User findByTel(String userTel) {
        return userDao.findByUserTel(userTel);
    }

    @Override
    public boolean add(User user) {
        user.setUserPassword(MD5Util.md5(user.getUserPassword()));
        return userDao.add(user)>0?true:false;
    }

    @Override
    public boolean update(User user) {
        user.setUserPassword(MD5Util.md5(user.getUserPassword()));
        return userDao.add(user)>0?true:false;
    }

    @Override
    public boolean usertest(String userTel, String userName, String userIdNumber) {
        boolean flag = false;
        //通过电话查询
        System.out.println(userTel);
        User user = userDao.findByUserTel(userTel);
        System.out.println(user);
        //判断姓名是否一致
        if (user.getUserName().equals(userName)){
            //判断输入的身份证是否一致
            if (user.getUserIdNumber().equals(userIdNumber)){
                //身份验证成功
                  flag = true;
            }
        }
        return flag;
    }
}
